<script setup>
import { ref } from 'vue';
import { getTaskListAPI } from '@/api/task'
//任务列表数据
const pickupList = ref([])
//任务类别接口参数
const pickupData = {
  page:1,
  pageSize:10,
  status:2
}
//总页数
const totalPage = ref(1)
//控制下拉刷新的加载
const isTriggered = ref(false)
 // 在途列任务列表是否为空
 const isEmpty = ref(false)
 
//获取任务列表数据
const getPickupList = async ()=>{
  const {data} = await getTaskListAPI(pickupData)
  // console.log(data);
  pickupList.value = data.items
  totalPage.value = data.pages
}
getPickupList()

// 上拉刷新
const onScrolltolower = async()=>{
  if (pickupData.page>=totalPage.value) return uni.showToast({ title: '没有更多数据了',icon: 'none', mask: true})
  pickupData.page++
  const {data} = await getTaskListAPI(pickupData)
  pickupList.value=[...pickupList.value,...data.items]
}

// 下拉刷新
const onRefresherrefresh = async()=>{
  isTriggered.value = true
  pickupData.page=1
  pickupList.value = []
  await getPickupList()
  isTriggered.value = false
}


</script>
<template>
  <scroll-view scroll-y refresher-enabled class="scroll-view" @scrolltolower="onScrolltolower" :refresher-triggered="isTriggered" @refresherrefresh="onRefresherrefresh">
    <view class="scroll-view-wrapper" v-for="item in pickupList" :key="item.id">
      <view class="task-card">
        <navigator hover-class="none" :url="`/subpkg_task/detail/index?id=${item.id}`">
          <view class="header">
            <text class="no">任务编号:{{item.id}}</text>
          </view>
          <view class="body">
            <view class="timeline">
              <view class="line"
                >{{item.startAddress}}</view
              >
              <view class="line">{{item.endAddress}}</view>
            </view>
          </view>
        </navigator>
        <view class="footer">
          <view class="label">到货时间</view>
          <view class="time">{{item.planArrivalTime}}</view>
          <navigator
          v-if="item.status === 2"
            hover-class="none"
            :url="`/subpkg_task/delivery/index?id=${item.id}`"
            class="action"
          >
            交付
          </navigator>
          <navigator
            v-if="item.status === 4"
            hover-class="none"
            :url="`/subpkg_task/record/index?transportTaskId=${item.transportTaskId}`"
            class="action"
          >
            回车登记
          </navigator>
        </view>
      </view>
 
      <view v-if="isEmpty" class="task-blank">无在途货物</view>
    </view>
  </scroll-view>
</template>

<style lang="scss" scoped>
  @import './styles.scss';
</style>
